(**************************************************************************)
(*                                                                        *)
(*  Copyright (C) Jean-Christophe Filliatre                               *)
(*                                                                        *)
(*  This software is free software; you can redistribute it and/or        *)
(*  modify it under the terms of the GNU Library General Public           *)
(*  License version 2, with the special exception on linking              *)
(*  described in file LICENSE.                                            *)
(*                                                                        *)
(*  This software is distributed in the hope that it will be useful,      *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *)
(*                                                                        *)
(**************************************************************************)

(** A persistent union-find data structure.

   The datatype [t] maintains a partition of the set [0,1,...,n-1],
   where [n] is the value passed to [create]. *)

(** A partition of a set of integers from [0] to a particular [n - 1]. *)
type t

(** [create n] is a fresh partition whose equivalence classes are singleton. *)
val create : int -> t

(** [find t x] returns the representant of the equivalence class of [x]. *)
val find : t -> int -> int

(** [union t x1 x2] merges the equivalence classes of [x1] and [x2]. *)
val union : t -> int -> int -> t

(** [extend t n] extends the set of integers of [t] to handle integers from
    [0] to [n-1]. This function assumes that [t] is working on integers
    from [0] to [m-1] with [m < n]. *)
val extend : t -> int -> t
